package com.guoz.excel;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import sun.security.ssl.Debug;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author guozhi
 * @Date 2019/7/30 15:26
 * @Description TODO
 */

@Controller
public class TestController {

    @RequestMapping("/")
    public String test(){
        return "index.html";
    }

    /**
     * 获取excel内容
     * @param file
     * @return
     */
    @RequestMapping("/excel")
    @ResponseBody
    public String getExcelContetn(@RequestParam("file") MultipartFile file) throws Exception {
        List<ExcelPOJO> result = new ArrayList<>();
        ResolveExcel<ExcelPOJO> resolveExcel = new ResolveExcel<ExcelPOJO>(file, ExcelPOJO.class);
        resolveExcel.forEach((item)->{
            result.add((ExcelPOJO) item);
        });
        return result.toString();
    }
}
